package online.westonline.com.westonline.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import online.westonline.com.westonline.R;

/**
 *
 * Created by xiatao on 2018/7/25.
 */

public class NodePerviewadapter extends RecyclerView.Adapter<NodePerviewadapter.NodePerviewViewHolder>
{
    private List<String> paths = new ArrayList<>();
    private MyPerviewAdpter.clicktodelte clicktodelte;
    private MyPerviewAdpter.clicktoadd clicktoadd;
    //预留的+号
    private int BOTTOM_VIEW=1;
    public void setPaths(List<String> paths) {
        this.paths = paths;
    }

    public void setClicktoadd(MyPerviewAdpter.clicktoadd clicktoadd) {
        this.clicktoadd = clicktoadd;
    }

    public void setClicktodelte(MyPerviewAdpter.clicktodelte clicktodelte) {
        this.clicktodelte = clicktodelte;
    }

    @NonNull
    @Override
    public NodePerviewadapter.NodePerviewViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.periview_item, parent, false);
            return new NodePerviewadapter.NodePerviewViewHolder(view);
        }

    }

    @Override
    public void onBindViewHolder(@NonNull NodePerviewadapter.NodePerviewViewHolder holder, int position) {
            Glide.with(holder.itemView.getContext()).load(new File(paths.get(position))).into(holder.imgPreiview);
    }



    @Override
    public int getItemCount() {
        return paths == null ? 0 : paths.size();
    }

    class NodePerviewViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_bage)
        ImageView imgBage;
        @BindView(R.id.img_preiview)
        ImageView imgPreiview;
        public NodePerviewViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (clicktodelte!=null)
                    {
                        clicktodelte.delete(getLayoutPosition(),paths.get(getLayoutPosition()));
                    }
                }
            });
        }
    }

}
